package com.example.practical_training_projects.mapper;

import com.example.practical_training_projects.entity.pc;
import com.example.practical_training_projects.entity.user;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface pcMapper {
    @Select("select * from pc")
    List<pc> getAllpc();

    @Insert("insert into pc(pc_name, pc_uid, pc_password, pc_sex, pc_phone, pc_email, pc_work, picture)\n" +
            " values (#{pc_name}, #{pc_uid}, #{pc_password}, #{pc_sex}, #{pc_phone}, #{pc_email}, #{pc_work}, #{picture})")
    Integer insertPc(pc pc);

    @Delete("delete from pc where pc_uid=#{pc_uid}")
    Integer deletePc(Integer pc_uid);

    @Update("update pc set pc_name=#{pc_name}, pc_password=#{pc_password}, pc_sex=#{pc_sex}, " +
            "pc_email=#{pc_email}, pc_phone=#{pc_phone}, pc_work=#{pc_work},picture=#{picture} where pc_uid=#{pc_uid}")
    Integer updatePc(pc pc);

    @Select("select * from pc where pc_name like '%${pc_name}%'")
    List<pc> getpcBYName(String pc_name);

    @Select("select * from  pc where pc_uid = #{pc_uid}")
    pc findPcid(Integer pc_uid);


    @Mapper
    public interface PcMapper {
        @Select("SELECT * FROM pc WHERE pc_name = #{pc_name} and user_password = #{user_password}")
        pc authenticatePc(@Param("pc_name") String pcName, @Param("user_password") String password);
    }


    @Select("SELECT * FROM pc WHERE pc_name = #{pc_name} and pc_password = #{pc_password}")
    pc authenticatePc(@Param("pc_name") String pcName, @Param("pc_password") String password);
}
